package com.tjp.eight.ui.fragment.loginreg;

import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/3/1.
 */
public class LogPresenter extends BasePresenterImpl<LoginView> {
    private RegService regService = RegNetWork.getRetrofit(UrlConstant.BaseUrl).create(RegService.class);

    public LogPresenter(LoginView loginView) {
        attachView(loginView);
    }

    public void toRegPhone(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(regService.toReg(requestBody), new SubscribeCallBack<>(new NetCallBack<RegResultModel>() {
            @Override
            public void onSuccess(RegResultModel model) {
                view.RegSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.RegFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void toLoginWX(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(regService.toLoginWX(requestBody), new SubscribeCallBack<>(new NetCallBack<LoginResultModel>() {
            @Override
            public void onSuccess(LoginResultModel model) {
                view.LoginSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.LoginFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void toLoginPhone(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(regService.toLoginPhone(requestBody), new SubscribeCallBack<>(new NetCallBack<LoginResultModel>() {
            @Override
            public void onSuccess(LoginResultModel model) {
                view.LoginSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.LoginFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
}
